#include "AbstractState.hpp"
#include "Application.hpp"

namespace MA {

AbstractState::AbstractState()
    : m_app(nullptr) {

}

AbstractState::~AbstractState() {
    m_app = nullptr;
}

void AbstractState::bindApp(Application* app) {
    m_app = app;
}

void AbstractState::handleEvent() {
    SDL_Event event;
    if (SDL_PollEvent(&event)) {
        switch (event.type) {
        case SDL_KEYDOWN:
            onKeyDown(event.key.keysym.sym);
            break;
        case SDL_KEYUP:
            onKeyUp(event.key.keysym.sym);
            break;
        case SDL_MOUSEBUTTONDOWN:
            onMouseDown(event.button.button, event.button.x, event.button.y);
            break;
        case SDL_MOUSEBUTTONUP:
            onMouseUp(event.button.button, event.button.x, event.button.y);
            break;
        case SDL_MOUSEMOTION:
            onMouseMotion(event.motion);
            break;
        case SDL_QUIT:
            m_app->setRunning(false);
            break;
        default:
            onDefault(event);
            break;
        }
    }
}

}
